package example.designpattern.memento.self;

//发起人兼负责人
public class OriginatorCaretaker {

  public String state;

  public void changeState(String state) {

    this.state = state;
  }

  //创造快照
  public Memento createMemento() {

    return new Memento(this);
  }

  //恢复状态
  public void recoverMemento(IMemento memento) {

    Memento m = (Memento) memento;
    changeState(m.state);
  }

  //内部类实现备忘录
  private class Memento implements IMemento {

    private String state;

    private Memento(OriginatorCaretaker originatorCaretaker) {

      this.state = originatorCaretaker.state;
    }

  }

}
